package com.rtos.controller;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @Author: Redi
 * @Date: 2021/8/31 17:02
 * @Description:
 * by biubiu0002
 * 不同scene/view的root节点加载类
 *
 */
public class MainWindow extends BorderPane {

    public MainWindow() {
        try{
//            Parent fxmlNode = FXMLLoader.load(this.getClass().getResource("../fxml/MainWindow.fxml"));
            Parent fxmlNode = FXMLLoader.load(this.getClass().getResource("/com/rtos/fxml/MainWindow.fxml"));
            this.setCenter(fxmlNode);
        } catch (IOException exception) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, "error", exception);
        }
    }

    public static Parent loadMainView(){
        try {
//            Parent fxmlNode = FXMLLoader.load(MainWindow.class.getResource("../fxml/MainWindow.fxml"));
            Parent fxmlNode = FXMLLoader.load(MainWindow.class.getResource("/com/rtos/fxml/MainWindow.fxml"));
            return fxmlNode;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Parent loadProcessView(){
        try {
//            Pane fxmlNode = FXMLLoader.load(MainWindow.class.getResource("../fxml/ProcessWindow.fxml"));
            Pane fxmlNode = FXMLLoader.load(MainWindow.class.getResource("/com/rtos/fxml/MainWindow.fxml"));
//            TableView<Student> studentTable = new TableView<>();
//            Student a = new Student("a", 12);
//            Student b = new Student("b", 13);
//
//            ObservableList<Student> studentObservableList = FXCollections.observableArrayList();
//            studentObservableList.add(a);
//            studentObservableList.add(b);
//
//            TableColumn<Student,StringProperty> nameColumn = new TableColumn<>();
//            TableColumn<Student,IntegerProperty> ageColumn = new TableColumn<>();
//            studentTable.getColumns().addAll(nameColumn, ageColumn);
//            nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
//            ageColumn.setCellValueFactory(new PropertyValueFactory<>("age"));
//            studentTable.setItems(studentObservableList);
//            fxmlNode.getChildren().add(studentTable);
//            new Thread(()->{
//                while(true){
//                    for(Student stu:studentObservableList){
//                        stu.ageProperty().set(stu.ageProperty().get()-1);
//                    }
//                    try{TimeUnit.SECONDS.sleep(1);}catch(InterruptedException e){e.printStackTrace();}
//
//                }
//            },"Thread name").start();
//            a.nameProperty().setValue("biubiu");
            return fxmlNode;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


}
